/*
 * Copyright (c) 2013, Charles Santos da Silva <silva.charlessantos@gmail.com> -
 * scharlessantos.org
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE
 */
package org.scharlessantos.hermes;

import org.scharlessantos.hermes.logger.HFileLogger;
import org.scharlessantos.hermes.writer.HLevel;
import org.scharlessantos.hermes.writer.HWriter;

import java.io.File;

/**
 * Configure Hermes to log. <br>
 * HConfiguration is stateless <br>
 * <br>
 * Hermes is free open-source Java Logger.<br>
 * It receive this name because Hermes was the messenger of Olympians gods, so,
 * anybody better than Hermes to send system messages to programmer<br>
 * 
 * * <br>
 * Hermes is licensed by new BSD License. A notice of license can be saw below<br>
 * <br>
 * <i>
 * Copyright (c) 2012-2013, Charles Santos da Silva <silva.charlessantos@gmail.com> -
 * scharlessantos.org
 * All rights reserved.<br>
 * <br>
 * Redistribution and use in source and binary forms, with or without<br>
 * modification, are permitted provided that the following conditions are met:<br>
 * <br>
 * 1. Redistributions of source code must retain the above copyright notice,<br>
 * this list of conditions and the following disclaimer.<br>
 * 2. Redistributions in binary form must reproduce the above copyright<br>
 * notice, this list of conditions and the following disclaimer in the<br>
 * documentation and/or other materials provided with the distribution.<br>
 * <br>
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
 * POSSIBILITY OF SUCH DAMAGE<br>
 * </i>
 * 
 * @author Charles Santos da Silva
 */
public class HConfiguration {
	
	private static HConfiguration instance;
	
	/**
	 * Gets the instance of HConfiguration
	 * 
	 * @return instace of Hermes Configuration
	 */
	public static HConfiguration getInstance() {
		if (instance == null)
			instance = new HConfiguration();
		
		return instance;
	}
	
	protected HConfiguration() {
		
	}
	
	private String format = "[%-5s] %s.%s(%s:%d)@%d";
	private File   file   = null;
	
	/**
	 * Customize the format of log output <br>
	 * Args of log output are: <br>
	 * <i>String level name, String class name, String method name, String file
	 * name, Integer line number Integer Thread id</i> [ In this order ] <br>
	 * <br>
	 * The Default format is: [%-5s] %s.%s(%s:%d)@%d<br>
	 * Sample: <br>
	 * [INFO ] org.scharlessantos.derivative.swing.Main.main(Main.java:24)@1:
	 * Starting derivative
	 * 
	 * <br>
	 * <br>
	 * If the defaults log output dissatisfy you, you can implement your version of Hermes Logger
	 * Writer and says to Hermes to work with it. For this, uses:
	 * <ul>
	 * <li> {@link Hermes#removeDefaultConsoleLogger()}
	 * <li> {@link Hermes#removeDefaultFileLogger()}
	 * <li>
	 * {@link Hermes#addLogger(org.scharlessantos.hermes.writer.HWriter, org.scharlessantos.hermes.writer.HFilter)}
	 * (with your Writter and Filter implementation)
	 * </ul>
	 * 
	 * @param baseFormat format that Hermes default writers uses
	 * @see HWriter
	 * @see HLevel
	 */
	public void setBaseFormat(String baseFormat) {
		format = baseFormat;
	}
	
	/**
	 * Gets the format of output log configured to default HermesLoggerWriter works<br/>
	 * Args of log output are: <br>
	 * <i>String level name, String class name, String method name, String file
	 * name, Integer line number Integer Thread id</i> [ In this order ] <br>
	 * <br>
	 * The Default format is: [%-5s] %s.%s(%s:%d)@%d<br>
	 * Sample: <br>
	 * [INFO ] org.scharlessantos.derivative.swing.Main.main(Main.java:24)@1:
	 * Starting derivative
	 * 
	 * @return base format of output line log
	 */
	public String getBaseFormat() {
		return format;
	}
	
	/**
	 * Sets the file that {@link HFileLogger} will use to write logs.
	 * 
	 * @param file to write logs.
	 * @see HFileLogger
	 */
	public void setLogFile(File file) {
		this.file = file;
	}
	
	/**
	 * Gets the file that {@link HFileLogger} uses to write logs.
	 * 
	 * @return file that {@link HFileLogger} uses.
	 * @see HFileLogger
	 */
	public File getLogFile() {
		return file;
	}
}
